package edu.xidian.onlinedocument.views;

import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 通用返回类，规定后端发给前端的json报文的格式
 */

@Data
@NoArgsConstructor
public class Result {
    /**
     * 是否成功
      */
    private boolean success;
    /**
     * 返回码
     */
    private String code;
    /**
     * 返回信息
     */
    private String message;
    /**
     * 返回数据
     */
    private Object data;

    public Result(ResultCode result){
        this.success = result.success;
        this.code = result.code;
        this.message = result.message;
    }

    public Result(ResultCode result, Object data){
        this.success = result.success;
        this.code = result.code;
        this.message = result.message;
        this.data = data;
    }

    public static Result SUCCESS(){
        return new Result(ResultCode.SUCCESS);
    }

    public static Result FAILED(){
        return new Result(ResultCode.FAILED);
    }
}
